﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_Dangnhap2 : System.Web.UI.UserControl
{
    private UsersBLL usersBLL;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.usersBLL = new UsersBLL();

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Users user = null;

        string username = this.txtUsername.Text;
        string password = this.txtPassword.Text;

        user = this.usersBLL.GetIUsers.CheckLogin(username, password);

        if (user != null)
        {
            if (user.Role.IdRole == Constant.ROLE_ADMIN)
            {
                Session["Admin"] = user;
                Response.Redirect("Admin.aspx");
            
            }
            else if (user.Role.IdRole == Constant.ROLE_MOD)
            {
                Session["Mod"] = user;
                Response.Redirect("Admin.aspx");

            }
            else if (user.Role.IdRole == Constant.ROLE_USER)
            {
                Session["User"] = user;
                Response.Redirect("Home.aspx");

            }
        }
        else 
        {
            Response.Redirect("LoginFail.aspx");
        }
    }
}